<template>
  <div class="content lists">
    <scroll-view scroll-y @scrolltolower="toLow" @scroll="scroll" class="box">
      <ul>
        <li v-for="(item,index) in artList" :key="index">
          <!-- 无图 -->
          <a v-if="item.coverNumber===0" :href="'/pages/article/main?articleId='+item.articleId+'&&agentId='+item.agentId+'&&agentId='+item.agentId">
            <div class="no-cover">
              <div class="item-content">
                <h3 class="title">{{item.title}}</h3>
                <div class="userinfo">
                  <span>{{item.agentName}}</span>
                </div>
              </div>
            </div>
          </a>
          <!-- 单图 -->
          <a v-if="item.coverNumber===1" :href="'/pages/article/main?articleId='+item.articleId+'&&agentId='+item.agentId+'&&agentId='+item.agentId">
            <div class="one-cover">
              <div class="item-content">
                <div class="cover-box">
                  <div class="left">
                    <div class="title">{{item.title}}</div>
                    <div class="userinfo">
                      <span>{{item.agentName}}</span>
                    </div>
                  </div>
                  <div class="img">
                    <img :src="config.img + item.imgUrl" mode="widthFix">
                  </div>
                </div>
              </div>
            </div>
          </a>
          <!-- 多图 -->
          <a v-if="item.coverNumber===2" :href="'/pages/article/main?articleId='+item.articleId+'&&agentId='+item.agentId+'&&agentId='+item.agentId">
            <div class="more-cover">
              <div class="item-content clearfix">
                <h3 class="title">{{item.title}}</h3>
                <div class="cover-box">
                  <div class="img" v-for="(item2,index2) in item.imgUrl" :key="index2">
                    <img :src="config.img + item2" mode="widthFix">
                  </div>
                </div>
                <div class="userinfo">
                  <span>{{item.agentName}}</span>
                </div>
              </div>
            </div>
          </a>
        </li>
      </ul>
      <div class="bottom">
        <mp-loadmore not-content="亲，暂时没有内容~~~" v-if="!pload && artList.length < 1" />
        <mp-loadmore type="loading" v-if="pload" />
        <mp-loadmore not-content="亲，全部都给你了~~~" v-if="end" />
      </div>
    </scroll-view>
  </div>
</template>
<script>
import MpLoadmore from 'mp-weui/packages/loadmore'
import { getList } from '@/utils/api'
import { config } from '@/utils/config'
export default {
  components: {
    MpLoadmore
  },
  data () {
    return {
      artList: [],
      page: 1,
      pages: 0,
      end: false,
      pload: false,
      config: config
    }
  },
  methods: {
    async getList () {
      this.pload = true
      try {
        let res = await getList({
          pageSize: 5,
          pageNum: 1
        })
        let data = res.list.map(item => {
          if (item.imgUrl) {
            item.imgUrl = item.imgUrl.split(',')
          }
          return item
        })
        this.artList = this.artList.concat(data)
        this.pages = res.pages
        this.page++
      } catch (e) {
        console.log(e)
        this.pload = false
      }
      this.pload = false
    },
    toLow () {
      if (this.pload) {
        return false
      }
      if (this.page > this.pages) {
        this.end = true
        return false
      }
      this.pload = true
      setTimeout(() => {
        this.getList()
      }, 500)
    }
  },
  created () {
    this.getList()
    wx.setNavigationBarTitle({
      title: '推荐文章'
    })
  }
}
</script>
<style scoped lang="scss">
.lists {
  .title {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
  }

  .content {
    height: 100%;
  }

  .content > .box {
    height: 100%;
  }

  li {
    padding: 10px;
    border-bottom: 1px solid rgba(221, 221, 221, 0.6);
  }

  .item-content {
    padding: 5px;
  }

  .title {
    font-size: 30px;
    color: #333;
  }

  .one-cover .cover-box {
    display: flex;
    justify-content: space-between;
    margin: 0 -2px;
  }

  .one-cover .left {
    flex: 2;
    margin: 0 6px 0 2px;
  }

  .one-cover .img {
    flex: 1;
    overflow: hidden;
    margin: 0 2px;
    width: 120px;
    height: 80px;
  }

  .one-cover .img img {
    display: block;
    width: 100%;
    height: 100%;
    background: #f2f2f2;
  }

  .more-cover .cover-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 10px -2px 0 -2px;
  }

  .more-cover .img {
    flex: 1;
    overflow: hidden;
    margin: 0 2px;
    width: 120px;
    height: 80px;
  }

  .more-cover .img img {
    width: 100%;
    height: 100%;
    display: block;
    background: #f2f2f2;
  }

  .one-cover .right img {
    width: 100%;
    vertical-align: middle;
  }

  .userinfo span {
    font-size: 24px;
    color: rgb(153, 153, 153);
    margin-right: 15px;
  }

  .loading {
    font-size: 24px;
    text-align: center;
    color: #ccc;
  }

  .bottom {
    padding-bottom: 10px;
  }
}
</style>

